package Utils;

import java.io.File;

import Utils.FromSignedToUnsigned;
import Utils.StringUtil;



public class GenUtils {
//	public static String genId(int abc) {
//	
//		Calendar calen = Calendar.getInstance();
//		return calen.get(Calendar.YEAR) + calen.get(Calendar.MONTH) + calen.get(Calendar.DAY_OF_MONTH)+"_"
//				+ Random.randomString(5) + Random.randomString(5);
//	}

	/***************************************************************************
	 * gen
	 * 
	 * @return
	 */
	
	public static String genPathByAccountId(String accountId){
		String first = accountId.substring(accountId.length()-2,accountId.length()-1);
		String middle = accountId.substring(accountId.length()-3,accountId.length()-2);
		String path =  Constant.FOLDER_IMG+"/"+first+"/"+middle;
		File f = new File (path);
		if(!f.exists()){
			f.mkdirs();
		}
		return path;
	}
	public static String genPathByPictureId(String pictureId){
		String first = pictureId.substring(pictureId.length()-2,pictureId.length()-1);
		String middle = pictureId.substring(pictureId.length()-3,pictureId.length()-2);
		String path =  Constant.FOLDER_IMG+"/"+first+"/"+middle;
		File f = new File (path);
		if(!f.exists()){
			f.mkdirs();
		}
		return path;
	}
	public static String genPathByAccountId2(String accountId){
		String first = accountId.substring(accountId.length()-2,accountId.length()-1);
		String middle = accountId.substring(accountId.length()-3,accountId.length()-2);
		return  first+"/"+middle;
	}
	public static String genClipPath(String clipId,String filename){
		String first = clipId.substring(clipId.length()-2,clipId.length()-1);
		String middle = clipId.substring(clipId.length()-3,clipId.length()-2);
		return  Constant.FOLDER_CLIP+"/"+first+"/"+middle+"/"+filename;
	}
	
	public static String genLinkView(String newsid){
		return "?act=detail&newsid="+newsid;
	}
	public static String genLinkImg(String newsId, String filename){
		return Constant.DATAPATH+"/"+genPathByAccountId2(newsId)+"/"+filename;
	}
	public static String genLinkView(String newsid, String title){
		return "chi-tiet/"+newsid+"/"+StringUtil.filterTitle(FromSignedToUnsigned.toUnsigned(title))+"/";
	}
	
	
	
	public static String genPathByClipId(String clipId){
		String first = clipId.substring(clipId.length()-2,clipId.length()-1);
		String middle = clipId.substring(clipId.length()-3,clipId.length()-2);
		String path =  Constant.FOLDER_CLIP+"/"+first+"/"+middle;
		File f = new File (path);
		if(!f.exists()){
			f.mkdirs();
		}
		return path;
	}
}
